#include "DynamicArray.h"
#include<iostream>
DynamicArray::DynamicArray(int capacity):size(0),capacity(capacity)
{
    array=new ElementType[capacity];    

}

DynamicArray::~DynamicArray()
{
    delete [] array;

}

void DynamicArray::InSertTail(const ElementType &element)
{
    //扩容
    if(size>=capacity)
    {   capacity*=2;
        ElementType*newp=new ElementType[capacity];
        for (int i = 0; i < size; i++)
        {
            newp[i]=array[i];
        }
        delete[]array;
        array=newp;
    }
    array[size++]=element;

}

void DynamicArray::show()
{

    for(int i=0;i<size;i++)
    {
        std::cout<<array[i]<<" ";


    }
    std::cout <<std::endl;
}

DynamicArray::DynamicArray(const DynamicArray&a)
{
    size=a.size;
    capacity=a.capacity;
    array=new ElementType[capacity];
    for(int i=0 ;i<size;i++)
    {
        array[i]=a.array[i];
    }

}

void DynamicArray::operator=(const DynamicArray &a)
{
    delete []array;
    size=a.size;
    capacity=a.capacity;
    array=new ElementType[capacity];
    for(int i=0 ;i<size;i++)
    {
        array[i]=a.array[i];
    }
}
